const { cloud } = getApp();
Page({
  cloud,
  data: {
    List:[
      {id:"lyl",url:"//img30.360buyimg.com/zx/jfs/t1/93151/5/16459/362864/5e7c4f3cE397fbcec/5d4c77d7ae076f4d.png",label:"lyl",value:"lyl"},
      {id:"yly",url:"//img30.360buyimg.com/zx/jfs/t1/87396/12/16276/481257/5e7c4f3eE84019a4b/b786162808de767b.png",label:"yly",value:"yly"},
      {id:"lly",url:"//img12.360buyimg.com/zx/jfs/t1/108459/21/10194/511137/5e7c4f3eE56cdf21d/add6463b08a78ba2.png",label:"lly",value:"lly"},
    ],
    auditCode:1,
    bigImgUrl:"",
    showBigImg:false,
    showHelpPop:false,
    filters:[
      {
        label:"全部",
        value:"lyl"
      },
      {
        label:"通过",
        value:"yly"
      },
      {
        label:"拒绝",
        value:"lly"
      }
      
    ],
    pageNum:1,
    auditList:"",
    auditListT:"",
    pageNumT:1,
    auditListS:'',
    pageNumS:1,
    pageList:'',
    pageListS:"",
    pageListT:""
  },
  onLoad() {
    this.handleChangeCodeF()
  },

  changePage(e){
    if(e.target.dataset.type=="prev"){
      // 上一页
      this.setData({
        pageNum:this.data.pageNum-1<1?1:this.data.pageNum-1
      },()=>{
          this.handleChangeCodeF()
      })
    }else{
      this.setData({
        pageNum:this.data.pageNum+1>this.data.pageList.pageCount?this.data.pageList.pageCount:this.data.pageNum+1
      },()=>{  
          this.handleChangeCodeF()
      })
    }
  },

  changePageT(e){
    if(e.target.dataset.type=="prev"){
      // 上一页
      this.setData({
        pageNumT:this.data.pageNumT-1<1?1:this.data.pageNumT-1
      },()=>{
          this.handleChangeCodeT()
      })
    }else{
      this.setData({
        pageNumT:this.data.pageNumT+1>this.data.pageListT.pageCount?this.data.pageListT.pageCount:this.data.pageNumT+1
      },()=>{
          this.handleChangeCodeT()
      })
    }
  },

  changePageS(e){
    if(e.target.dataset.type=="prev"){
      // 上一页
      this.setData({
        pageNumS:this.data.pageNumS-1<1?1:this.data.pageNumS-1
      },()=>{
          this.handleChangeCodeS()
      })
    }else{
      this.setData({
        pageNumS:this.data.pageNumS+1>this.data.pageListS.pageCount?this.data.pageListS.pageCount:this.data.pageNumS+1
      },()=>{
          this.handleChangeCodeS()
      })
    }
  },

  copyId(e){
    console.log(e.target.dataset._id.value)
     my.setClipboard({
      text: e.target.dataset._id.value
    });
  },
  handleClick(e){


  if(e.target.dataset.code==1){
    my.confirm({
      title:"是否确认通过审核",
      success:(myres)=>{
        console.log(myres)
        if(myres.confirm){
            console.log(e.target.dataset._id.record._id,e.target.dataset.code)
            // 通过
            const options = {
              _id:e.target.dataset._id.record._id,
              status:e.target.dataset.code
            };
            console.log(options)
            cloud.function.invoke('business', options, 'approve').then(res => {
              console.log('审核成功',res)
              if(res.code==0){
                this.handleChangeCodeF()
                  my.showToast({content:"审核成功"});
                }
              })
            }
        }
      // 
    })
  }else if(e.target.dataset.code==2){
    my.confirm({
      title:"是否确认拒绝",
      success:(myres)=>{
        if(myres.confirm){
          // 拒绝
        const options = {
          _id:e.target.dataset._id.record._id,
          status:e.target.dataset.code
        };
        console.log(options)
        cloud.function.invoke('business', options, 'approve').then(res => {
          console.log('审核成功',res)
          if(res.code==0){
            this.handleChangeCodeF()
              my.showToast({content:"审核成功"});
            }
          })
        }
      }
    });
  }
},
  handleChangeCodeF(){

    const options = {
      'status':0,
      pageNum:this.data.pageNum
    };
    console.log(options)
    cloud.function.invoke('business', options, 'getWorkList').then(res => {
      console.log('查询成功',res)
      if(res.code==0){
        this.setData({
          auditList:res.data.list,
          pageList:res.data
        })
      }
    })


    this.setData({
      auditCode:1
    })
  },
  handleChangeCodeT(){
        const options = {
      'status':1,
      pageNum:this.data.pageNumT
    };
    console.log(options)
    cloud.function.invoke('business', options, 'getWorkList').then(res => {
      console.log('查询成功',res)
      if(res.code==0){
        this.setData({
          auditListT:res.data.list,
          pageListT:res.data
        })
      }
    })
    this.setData({
      auditCode:2
    })
  },
  handleChangeCodeS(){
    const options = {
      'status':2,
      pageNum:this.data.pageNumS
    };
    console.log(options)
    cloud.function.invoke('business', options, 'getWorkList').then(res => {
      console.log('查询成功',res)
      if(res.code==0){
        this.setData({
          auditListS:res.data.list,
          pageListS:res.data
        })
      }
    })
    this.setData({
      auditCode:3
    })
  },
  handleScaleImg(e){
    console.log(e.target.dataset.url)
    this.setData({
      bigImgUrl:e.target.dataset.url?e.target.dataset.url:"",
      showBigImg:true
    })
  },
  handleCloseMask(){
    this.setData({
      showBigImg:false
    })
  },
  handleOpenHelp(){
    this.setData({
      showHelpPop:true
    })
  },
  handleCloseHelpMask(){
    this.setData({
      showHelpPop:false
    })
  },
});
